﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList arr = new ArrayList() { "abc", "adc", "apc", 123, 22, 11 };
            //在集合arr内查找abc
            int index = arr.IndexOf("abc");
            if (index != -1)
            {
                Console.WriteLine("确实有abc这玩意!");
            }
            else
            {
                Console.WriteLine("别想了，压根没这玩意！");
            }
            Console.WriteLine();
            //将arr下标为偶数添加到另一个集合(arr1)
            ArrayList arr1 = new ArrayList();
            
            for (int i = 0; i < arr.Count; i = i + 2)
            {
                arr1.Add(arr[i]);
            }
            foreach (var n in arr1)
            {
                Console.WriteLine(n);
            }
            Console.WriteLine();
            //在集合arr的第一个元素后插入三个元素
            ArrayList arr2 = new ArrayList() { 1,2,3};
            arr.InsertRange(1,arr2);
            foreach(var m in arr)
            {
                Console.WriteLine(m);
            }
            //用sort将arr2集合中的元素排序
            Console.WriteLine();
            arr2.Sort();
            foreach(var j in arr2)
            {
                Console.WriteLine(j);
            }
            Console.WriteLine();
            //用reverse将sort排序后的结果倒序
            arr2.Reverse();
            foreach(var k in arr2)
            {
                Console.WriteLine(k);
            }
            Console.WriteLine();
            //用IComparer方式排序输出string
            ArrayList list = new ArrayList() { "ac","ag","cd",132,234,33};
            MyComparer myComparer = new MyComparer();
            list.Sort(myComparer);
            foreach(var l in list)
            {
                Console.WriteLine(l);
            }   
        }
        
        
    }
}
